﻿using UnityEngine;

public class FinalSword:Npc
{
    [Header("coll")]
    public GameObject collObj;
    [Header("拥有超脱石")]
    public SayData data1;
    [Header("未拥有超脱石")]
    public SayData data2;
    [Header("魔气")]
    public GameObject magicEff;
    [Header("无剑状态")]
    public GameObject noObj;

    private void Start()
    {
        collObj = transform.Find("CheckPosOne").gameObject;

        //隐藏
        collObj.GetComponent<Collider2D>().enabled = false;

        //如果拥有了剑
        if(GameManager.Instance.haveSword)
        {
            DesMagicEff();
            GetSword();
        }
        else
        {
            magicEff.SetActive(true);
            noObj.SetActive(false);
        }
    }
    private void OnMouseDown()
    {
        SceneItemManager.instance.clickEnemyRight = true;
        collObj.GetComponent<Collider2D>().enabled = true;
        SceneItemManager.instance.SetClickEnemy(gameObject);
    }
    //打开UI
    public void OpenUI()
    {
        //如果已经拔出
        for (int i = 0; i < SceneItemManager.instance.npcs.Count; i++)
        {
            Npc sc = SceneItemManager.instance.npcs[i].GetComponent<Npc>();
            if (sc!=null&&sc.npcName == npcName)
            {
                if(SceneItemManager.instance.npcData[i]==false)
                {
                    return;
                }
            }
        }
        //查看是否拥有超脱石
        if(GameManager.Instance.stoneNum>0)
        {
            sayData=data1;
        }
        else
        {
            sayData=data2;
        }
        sayData.type=SayType.Npc;
        //打开SayPanel
        PanelManager.Open<SayPanel>(sayData);
        //关闭碰撞enable
        collObj.GetComponent<Collider2D>().enabled = false;
    }
    //驱除魔气
    public void DesMagicEff()
    {
        magicEff.SetActive(false);
    }
    //拨出剑
    public void GetSword()
    {
        GetComponent<SpriteRenderer>().enabled=false;
        noObj.SetActive(true);

        GameManager.Instance.haveSword=true;
        GameManager.Instance.player.OpenFinalSword();
    }
}